﻿using RayDen.Library.Entity;
using RayDen.Library.Entity.Scene;
using RayDen.Library.Entity.SceneGraph;

namespace RayDen.Optix.Engine.Scene.Builders
{

    public abstract class SceneBuilderComponentBase : DependentComponentBase
    {
        public SceneBuilder Builder { get; set; }
        
    }
    public abstract class SceneBuilderComponentBase<TElement> : SceneBuilderComponentBase, INodeVisitor, ISceneBuilder
        where TElement : SceneGraphElement
    {

        internal SceneInfo Owner
        {
            get { return this.BaseContainer.Get<SceneInfo>(); }
        }

        internal SceneGraphInfo SceneGraph
        {
            get { return this.BaseContainer.Get<SceneGraphInfo>(); }
        }




        public void Setup(SceneInfo scn, SceneGraphInfo grp)
        {
            this.BaseContainer.Populate(scn, grp);
        }

        public void Visit(SceneGraphElement node)
        {
            if (node is TElement)
                this.VisitInternal((TElement)node);
        }

        protected abstract void VisitInternal(TElement node);

        public virtual void Add<TSceneElement>(TSceneElement item) where TSceneElement : class
        {
            
        }
    }

    public class MeshBuilder : SceneBuilderComponentBase<GeometryInstanceNode>
    {
        protected override void VisitInternal(GeometryInstanceNode node)
        {
            var geoData = (GeometryInfo)SceneGraph.ResolveDataNode<GeometryElementNode>(node).GetDataItem();
            //Transform
        }
    }


    public class CameraBuilder : SceneBuilderComponentBase<CameraNode>
    {
        protected override void VisitInternal(CameraNode node)
        {
            this.Builder.Cameras.Add((CameraInfo)node.GetDataItem());
        }
    }

    public class VolumeBuilder : SceneBuilderComponentBase<VolumeNode<VolumeMaterialInfo>>
    {
        protected override void VisitInternal(VolumeNode<VolumeMaterialInfo> node)
        {
            //this.Builder.VolumeMats.Add((VolumeMaterialInfo)node.GetDataItem());
        }
    }
}